#!/bin/bash

app=$(cf apps | grep -e '\/\d' | cut -d' ' -f1 | fzf +m)

credentials=$(cf_env_vcap_services $app | jq ".VCAP_SERVICES.redis[0].credentials")
# echo $credentials

host=$(echo $credentials | jq ".host" | tr -d '"')
port=$(echo $credentials | jq ".port")
password=$(echo $credentials | jq ".password" | tr -d '"')

echo "connecting to host: '${host}' port: '${port}' pwd: '${password}'"

docker run --rm -ti --name rediscli \
    --net host \
    redis \
    redis-cli -h ${host} -p ${port} -a ${password}